<?php

session_start();


if (!defined('_VALID_MOS')) {
    define('_VALID_MOS', 1);
}


// đính kèm file định nghĩa các biến hằng số đường dẫn
require_once '../constant.php';

if (!isset($_SESSION["session"]["sUserName"])) {
    include_once ADMIN_COM . DS . 'com_login' . DS . 'index.php';
} else {

    include_once LIBRARIES_ENTITIES . DS . 'Configuration.php';
    include LIBRARIES_ENTITIES_GROUPFUNCTIONS;
    include LIBRARIES_ENTITIES_GROUPS;
    include LIBRARIES_ENTITIES_FUNCTIONS;
    include LIBRARIES_ENTITIES_DATABASE;


    $configuration = new Configuration();
    $xmlFile = ROOT . DS . 'configuration.xml';
    $configuration->getConfiguration($xmlFile);


    // create session
    $_SESSION["web_information"] = array(
        'siteName' => (string) $configuration->getSiteName(),
        'keyword' => (string) $configuration->getKeyWord(),
        'address' => (string) $configuration->getAddress(),
        'email' => (string) $configuration->getEmail(),
        'phoneNumber' => (string) $configuration->getPhoneNumber(),
        'marquee' => (string) $configuration->getMarquee(),
        'sales' => (string) $configuration->getSales()
    );


    //   get functions
    $db = new Database();
    $groupFunction = new GroupFunctions();
    $groupFunction->setGroupID($_SESSION["session"]["sGroupID"]);
    $rows = $groupFunction->getListByGroupID($db);

    
    // mảng danh sách lưu các hành động chức năng
    $groupFunctionsArray = array();
   
    for ($i = 0; $i < count($rows); $i++) {
        $groupFunctionsArray[$i] = array('groupID' => $rows[$i]->getGroupID(),
            'functionID' => $rows[$i]->getFunctionID(),
            'view' => $rows[$i]->getView(),
            'add' => $rows[$i]->getAdd(),
            'delete' => $rows[$i]->getDelete(),
            'update' => $rows[$i]->getUpdate(),
            'disable' => $rows[$i]->getDisable(),
            'enable' => $rows[$i]->getEnalble(),
            'highlight' => $rows[$i]->getHighlight(),
            'unhighlight' => $rows[$i]->getUnhighlight());
    }

    // create session
    $_SESSION["groupFunctions"] = $groupFunctionsArray;

    include_once("template/index.php");
}
?>